package com.kitchen
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class AbstractButton extends Sprite
	{
		protected var bitmap:Bitmap;
		public var h:Number;
		public var w:Number;
		public var checked:Boolean = false;
		
		public function AbstractButton(bitdata:BitmapData)
		{
			super();
			this.layout(bitdata);
			//this.addEventListener(MouseEvent.CLICK, onMouseClick);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			this.addEventListener(MouseEvent.MOUSE_UP, onMouseOver);
			this.useHandCursor = true;
			this.buttonMode = true;
		}
		
		public function setChecked(ck:Boolean):void{
			
		}
		
		protected function layout(bitdata:BitmapData):void{
			this.bitmap = new Bitmap(this.getBitmapData(bitdata));
			var shape:Shape = new Shape();
			shape.graphics.beginFill(0xffffff, 1);
			shape.graphics.drawRect(0, 0, this.w, this.h);
			shape.graphics.endFill();
			this.mask = shape;
			this.addChild(shape);
			this.addChild(this.bitmap);
		}
		
		protected function offsetX(ox:Number):void{
			this.bitmap.x = -ox;
		}
		
		protected function offsetY(oy:Number):void{
			this.bitmap.y = -oy;
		}
		
		protected function getBitmapData(bitdata:BitmapData):BitmapData{
			throw new Error('you must override this function in children class', 1);
		}
		
		protected function onMouseOver(me:MouseEvent):void{
			throw new Error('you must override this function in children class', 1);
		}
		
		protected function onMouseDown(me:MouseEvent):void{
			throw new Error('you must override this function in children class', 1);
		}
		
		protected function onMouseOut(me:MouseEvent):void{
			this.offsetX(0);
		}
		
	}
}